package cn.tedu._01yuncat.base.exception;

import cn.tedu._01yuncat.base.response.JsonResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public JsonResult doMethodArgumentNotValidException(MethodArgumentNotValidException e){
        String data = e.getBindingResult().getFieldError().getDefaultMessage();
        return JsonResult.fail(data);
    }
}
